﻿using DevExpress.XtraReports.UI;
using DevTeam;
using System;
using System.Data;
using System.Drawing;

namespace ConfExpert.Forms.Rapor
{
    public partial class xrTopKesim : DevExpress.XtraReports.UI.XtraReport
    {
        public xrTopKesim()
        {
            InitializeComponent();
        }

        public xrTopKesim(string BolunenTopIds)
            : this()
        {
            MyDataTopBolme.Merge(Session.DataManager.ExecuteDataSet("GetTopBolByBolunenTopId", BolunenTopIds));
            MyDataTopBolme.xTopBolme.Merge(MyDataTopBolme.Tables["Table"]);
            MyDataTopBolme.xTopBolmeLines.Merge(MyDataTopBolme.Tables["Table1"]);
            xrTopKesimDetail xrSubDetail1 = (xrTopKesimDetail)xrSubreport1.ReportSource;
            xrSubDetail1.fillTable(MyDataTopBolme.xTopBolmeLines);
            tcDate.Text = DateTime.Now.ToShortDateString();
        }

        public xrTopKesim(int CikisEmriId)
            : this()
        {
            MyDataTopBolme.Merge(Session.DataManager.ExecuteDataSet("GetBolunenTopByCikisEmriId", CikisEmriId));
            MyDataTopBolme.xTopBolme.Merge(MyDataTopBolme.Tables["Table"]);
            MyDataTopBolme.xTopBolmeLines.Merge(MyDataTopBolme.Tables["Table1"]);

            xrTopKesimDetail xrSubDetail1 = (xrTopKesimDetail)xrSubreport1.ReportSource;
            xrSubDetail1.fillTable(MyDataTopBolme.xTopBolmeLines, MyDataTopBolme.Tables["Table3"]);

            DataRow drHeader = MyDataTopBolme.Tables["Table2"].Rows[0];

            tcBrand.Text = drHeader["Brand"].ToString();
            tcSezon.Text = drHeader["Sezon"].ToString();
            tcCikisEmri.Text = drHeader["CikisEmriId"].ToString();
            tcAtolye.Text = drHeader["Atelye"].ToString();
            tcDosyaNo.Text = drHeader["DosyaNo"].ToString();
            tcCikisTipi.Text = drHeader["CikisTipi"].ToString();
            tcTalepTarihi.Text = drHeader["TalepTarihi"].ToString();
            tcTalepEden.Text = drHeader["TalepEden"].ToString();
            tcDate.Text = DateTime.Now.ToShortDateString();
        }

        private void xrSubreport1_BeforePrint(object sender, System.Drawing.Printing.PrintEventArgs e)
        {
            ((xrTopKesimDetail)((XRSubreport)sender).ReportSource).RollId.Value =
       Convert.ToInt32(GetCurrentColumnValue("RollId"));
        }

        private void xrTable10_BeforePrint(object sender, System.Drawing.Printing.PrintEventArgs e)
        {
            int a = 0;
            xrTable10.HeightF = 149F;
            Detail.HeightF = 150;
            if (MyDataTopBolme.xTopBolmeLines.Rows.Count > 0)
                a = MyDataTopBolme.xTopBolmeLines.Select("RollId=" + GetCurrentColumnValue("RollId").ToString()).Length;
            if (a > 2)
            {
                xrTable10.HeightF = a * 75F - 1;
            }
        }

        private void xrTable1_BeforePrint(object sender, System.Drawing.Printing.PrintEventArgs e)
        {
            int a = 0;
            xrTable1.HeightF = 149F;
            Detail.HeightF = 150F;
            if (MyDataTopBolme.xTopBolmeLines.Rows.Count > 0)
                a = MyDataTopBolme.xTopBolmeLines.Select("RollId=" + GetCurrentColumnValue("RollId").ToString()).Length;
            if (a > 2)
            {
                xrTable1.HeightF = a * 75F - 1;
            }
        }

        private void Detail_BeforePrint(object sender, System.Drawing.Printing.PrintEventArgs e)
        {
            Detail.HeightF = 150F;
        }

        private void xrTableCell20_BeforePrint(object sender, System.Drawing.Printing.PrintEventArgs e)
        {
            xrTableCell3.ForeColor = Color.Black;
            string RollId = GetCurrentColumnValue("RollId").ToString();
            bool IsCut = MyDataTopBolme.Tables["Table3"].Select("RollId = " + RollId).Length > 0;
            if (IsCut)
            {
                xrTableCell3.ForeColor = Color.Red;
                xrTableCell3.Text = xrTableCell3.Text + " *";
            }
        }
    }
}
